package com.hk;

import java.io.File;

import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;

import com.hk.global.PanelState;
import com.hk.global.SoundUrl;
import com.hk.panel.FirstPanel;
import com.hk.panel.GamePanel;
import com.hk.panel.LosePanel;
import com.hk.panel.SettingPanel;
import com.hk.panel.WinPannel;

public class BlackJack{
	public static String state;
	public static MainFrame mf;
	public static FirstPanel fp;
	public static SettingPanel sp;
	public static GamePanel gp;
	public static WinPannel wp;
	public static LosePanel lp;

	public static BasicPlayer player = new BasicPlayer();
	
	public BlackJack() {
		mf = new MainFrame();
		fp = new FirstPanel();
		gp = new GamePanel();
		sp = new SettingPanel();
		wp = new WinPannel();
		lp = new LosePanel();
		
		player = new BasicPlayer();
	}
	public void start() {
		state = PanelState.FIRST;
		update();
	}
	
	public static void setName(String userName)
	{
		gp.getNgLab().setNameLab(userName);
	}
	
	public static void update() {
		System.out.println(state);
		
		if ( state == PanelState.FIRST ) {
			mf.setContentPane(fp);
			playSound( SoundUrl.FIRST );
			System.out.println("start event!!");
		} else if ( state == PanelState.SETTING ) {
			mf.setContentPane(sp);
			playSound( SoundUrl.SETTING );
			System.out.println("setting event!!");
		} else if ( state == PanelState.PLAY ) {
			mf.setContentPane(gp);
			changeSound( SoundUrl.GAME );
			System.out.println("paly event!!");
		} else if ( state == PanelState.WIN ) {
			mf.setContentPane(wp);
			changeSound( SoundUrl.WIN );
			System.out.println("win event!!");
		} else if ( state == PanelState.LOSE ) {
			mf.setContentPane(lp);
			changeSound( SoundUrl.LOSE );
			System.out.println("lose event!!");
		}
	}
	
	public static void playSound(String fileName)
	{
		File mediaFile = new File( fileName );

		try{
			player.open(mediaFile);
			player.play();
		} catch(BasicPlayerException e){
			e.printStackTrace();
		}
	}
	public static void stopSound(){
		try{
			player.stop();
		} catch(BasicPlayerException e){
			e.printStackTrace();
		}
	}
	public static void changeSound(String fileName){

		File mediaFile = new File(fileName);
		try{
			player.open(mediaFile);
			player.play();
		} catch(BasicPlayerException e){
			e.printStackTrace();
		}
	}
}
